import { connect } from 'umi';
import { Link } from 'dva/router';

function List({ customers, dispatch }) {
  function deleteUserHandler(id) {
    dispatch({
      type: 'customers/deleteTable',
      payload: {
        key: id,
      },
    });
  }
  return (
    <div>
      <h1>List Page</h1>
      <Link to={'/employee' }>
              <button>新增</button>
            </Link>
      <ul>
        {customers.map((e) => (
          <li key={e.key}>
            {e.firstName}
            {e.lastName}
            {'  '}
            {e.address}
            {'  '}
            {e.age}
            {'  '}
            {e.address}
            <Link to={'/list/' + e.key}>
              <button>编辑</button>
            </Link>
            <Link to="/users">
              <button onClick={() => deleteUserHandler(e.key)}>删除</button>
            </Link>
          </li>
        ))}
      </ul>
    </div>
  );
}

export default connect(({ customers }) => ({ customers }))(List);
